package azheng.apps.starclouddemo;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.graphics.PathMeasure;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;

import com.plattysoft.leonids.ParticleSystem;

import azheng.apps.starclouddemo.demo.AnimationUtils;
import azheng.apps.starclouddemo.widget.SatelliteView;
import butterknife.BindView;
import butterknife.ButterKnife;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    @BindView(R.id.xing_core)
    ImageView xingCore;

    private float[] mCurrentPosition = new float[2];


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        xingCore.setOnClickListener(this);



        setAnimator();
        //添加视图加载完成监听，getLocationInWindow需等到视图加载完成后才能返回正确值，否则为0
    /*    xingCore.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                // TODO Auto-generated method stub
                startRotate();
            }
        });
*/
    }

    private void setAnimator() {
        //组合动画
        AnimatorSet animatorSet = new AnimatorSet();
        /**
         * 动画作用对象是 xingCore
         * 动画作用的对象的属性是X轴缩放
         * 动画效果是:放大到3倍,再缩小到初始大小
         */
        ObjectAnimator toViewAnimatorX = ObjectAnimator.ofFloat(xingCore, "scaleX", 1f, 1.2f, 1f);
        ObjectAnimator toViewAnimatorY = ObjectAnimator.ofFloat(xingCore, "scaleY", 1f, 1.2f, 1f);

        //设置动画重复次数 无限循环
        toViewAnimatorX.setRepeatCount(-1);

        //设置动画重复次数
        toViewAnimatorY.setRepeatCount(-1);

        ////两个动画同时开始
        animatorSet.play(toViewAnimatorX).with(toViewAnimatorY);
        //动画时间
        animatorSet.setDuration(4000);
        animatorSet.start();
    }

    private void setBtnXing() {
        RotateAnimation animation = new RotateAnimation(30f, 90f, 50f, 50f);
        animation.setDuration(1000);
        animation.setFillAfter(true);
        //设置动画重复次数
        animation.setRepeatCount(-1);
//        xing5.startAnimation(animation);
    }

    @Override
    public void onClick(View v) {
        new ParticleSystem(this, 30, R.drawable.baidian, 3000)
//		.setAcceleration(0.00013f, 270)
                .setAccelerationModuleAndAndAngleRange(0.00013f, 0.00013f, 250, 280)
                .setSpeedByComponentsRange(0f, 0f, 0.05f, 0.1f)
                .setFadeOut(200, new AccelerateInterpolator())
                .emitWithGravity(v, Gravity.BOTTOM, 30);
    }
}
